<?php

namespace App\Custom;

use App\Constants\Number;

/**
 * 可分页的
 */
trait Pageable
{
    public $page;

    public $page_size;

    public function getPage()
    {
        return (int)$this->page ?: Number::DEFAULT_PAGE;
    }

    public function getPageSize()
    {
        return (int)$this->page_size ?: Number::DEFAULT_PAGE_SIZE;
    }

    public function getOffset()
    {
        return ($this->getPage() - 1) * $this->getPageSize();
    }
}